<?php
//======================================================================================
//
// Function: Get devices
//
// Programmer: AR
// Date : 2024-11-15
//
// Copyright Reeft A/S (c) - 2024
//======================================================================================
// https://login.gps-tracker.dk/api/get_devices?lang=en&user_api_hash=$2y$10$SC.XMMJovzAiHijfPf/0F.AAatv6EBPw.4S0DbyQCUHNErB7qfd4q
//======================================================================================
// General
//======================================================================================
include "include/apikey.php";
//======================================================================================
// Get input
//======================================================================================
$parms = '?'
. 'lang=en'
. '&user_api_hash=' . $gsmKey
;
// Set URL
$url = $gsmUrl . '/' . 'get_devices';
// Add parms
$url = $url . $parms;
// echo $url;
// Create a new cURL resource
$ch = curl_init($url);
// Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HEADER, false); // we do not need headers
curl_setopt($ch, CURLOPT_NOBODY, false); // we don't need body
// Execute the GET request
$result = curl_exec($ch);
$error_msg = "";
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
}
// Close cURL resource
curl_close($ch);
$data = json_decode($result, true);
$returnResult = [];
$returnResult["error"] = $error_msg;
if ($error_msg == "") {
$returnResult["data"] = array();
$tmpKeyedArr = array();
// Create new data node from items
foreach ($data[0]['items'] as &$item)
{
$tmpArr = array();
$tmpID = $item["device_data"]["imei"];
$tmpKeyedArr[$tmpID] = array();
foreach ($item as $key => $value) {
$tmpArr[$key] = $value;
}
$returnResult["data"][] = $tmpArr;
}
}
echo json_encode($returnResult);